package top.glike.funct.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.glike.common.annotation.Log;
import top.glike.common.core.controller.BaseController;
import top.glike.common.core.domain.AjaxResult;
import top.glike.common.enums.BusinessType;
import top.glike.funct.domain.GbExcel;
import top.glike.funct.service.IGbExcelService;
import top.glike.common.utils.poi.ExcelUtil;
import top.glike.common.core.page.TableDataInfo;

/**
 * 表单管理Controller
 * 
 * @author Sophia
 * @date 2024-02-13
 */
@RestController
@RequestMapping("/funct/excel")
public class GbExcelController extends BaseController
{
    @Autowired
    private IGbExcelService gbExcelService;

    /**
     * 查询表单管理列表
     */
    // @PreAuthorize("@ss.hasPermi('funct:excel:list')")
    @GetMapping("/list")
    public TableDataInfo list(GbExcel gbExcel)
    {
        startPage();
        List<GbExcel> list = gbExcelService.selectGbExcelList(gbExcel);
        return getDataTable(list);
    }

    /**
     * 导出表单管理列表
     */
    // @PreAuthorize("@ss.hasPermi('funct:excel:export')")
    @Log(title = "表单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GbExcel gbExcel)
    {
        List<GbExcel> list = gbExcelService.selectGbExcelList(gbExcel);
        ExcelUtil<GbExcel> util = new ExcelUtil<GbExcel>(GbExcel.class);
        util.exportExcel(response, list, "表单管理数据");
    }

    /**
     * 获取表单管理详细信息
     */
    // @PreAuthorize("@ss.hasPermi('funct:excel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gbExcelService.selectGbExcelById(id));
    }

    /**
     * 新增表单管理
     */
    // @PreAuthorize("@ss.hasPermi('funct:excel:add')")
    @Log(title = "表单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbExcel gbExcel)
    {
        return toAjax(gbExcelService.insertGbExcel(gbExcel));
    }

    /**
     * 修改表单管理
     */
    // @PreAuthorize("@ss.hasPermi('funct:excel:edit')")
    @Log(title = "表单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbExcel gbExcel)
    {
        return toAjax(gbExcelService.updateGbExcel(gbExcel));
    }

    /**
     * 删除表单管理
     */
    // @PreAuthorize("@ss.hasPermi('funct:excel:remove')")
    @Log(title = "表单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gbExcelService.deleteGbExcelByIds(ids));
    }
}
